﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using StreetlightGames.XnaEngine;
using System.Runtime.Serialization;

namespace StreetlightGames.SpaceShooter.Patterns
{
    [DataContract]
    public class Hover : Pattern
    {        
        /// <summary>Gets or sets the Duration value</summary>
        public double Duration
        {
            get { return _duration; }
            set { _duration = value; }
        }
        private double _duration;
        
        private double _elapsedTime;

        public Hover()
        {
        }

        public override void Start()
        {
            _elapsedTime = 0;
            _duration = RandomHelper.NextDouble(2, 30);
            Ship.Velocity = Vector3.Zero;
            Ship.Rotation = Vector3.Zero;
            Ship.IsArmed = false;
        }

        public override void Update(GameTime gameTime)
        {
            if (Ship.Wave.IsFormationComplete)
            {
                _elapsedTime += gameTime.ElapsedGameTime.TotalSeconds;
            }
            if (_elapsedTime > _duration)
            {
                NextPattern = new Attack();
                NextPattern.NextPattern = this;
                MoveToNextPattern(gameTime);
            }
            else
            {
                Ship.Position = new Vector3(Ship.Position.X + (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds % (double)MathHelper.TwoPi), Ship.Position.Y, Ship.Position.Z);
                base.Update(gameTime);
            }
        }
    }
}
